package com.yiyuan.weixin.weixinInservice.Iml;

import com.yiyuan.weixin.weixinInservice.service.WXAccessService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by admin on 2017/3/28.
 */
public abstract class AbsWXAccessService implements WXAccessService{
    /*******
     * 接收微信端发送过来的xml数据
     * @param req
     * @return
     * @throws IOException
     */
    public String getStringFromWX(HttpServletRequest req) throws IOException {
        req.setCharacterEncoding("UTF-8");
        /** 读取接收到的xml消息 */
        StringBuffer sb = new StringBuffer();
        InputStream is = req.getInputStream();
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        String s = "";
        while ((s = br.readLine()) != null) {
            sb.append(s);
        }
        System.out.println("解析之前："+sb.toString());
        return sb.toString(); //次即为接收到微信端发送过来的xml数据

    }

}
